import Node from './Node'
import { Minder }  from './Minder'
import MinderLayout from './layout/MinderLayout'
import {Stack} from './command/command'
import toolBar from './event/toolbar'
import mindEvent from './event/mindEvent'
import navigator from './event/navigator'
import Clock from './clock'

var zr=zrender.init(document.getElementById('mindEditor'),{
  renderer:'canvas'
});

//添加代码
/*
var data={
    id:1,
    text:'根节点',
    textFill:'#fff',
    textPadding:[15,20,15,20],
    fontSize:18,
    textBackgroundColor:'#00aaff',
    textBorderRadius:4,
    textOffset:[10,6],
    children:[
        {
            id:2,
            text:'节点2',
            children:[
               {
                  id:4,
                  text:'节点4'
                },
                {
                   id:6,
                   text:'节点6'
                 }
            ]
        },
        {
            id:3,
            text:'节点3',
            children:[
               {
                  id:5,
                  text:'节点5'

                },
                {
                   id:7,
                   text:'节点7'
                 }
            ]
        },
    ]
};
*/

function initMinder(data) {
	data.textFill = '#fff';
	data.textPadding = [15,20,15,20];
	data.fontSize = 18;
	data.textBackgroundColor = '#00aaff';
	data.textBorderRadius = 4;
	data.textOffset = [10,6];
	
	JSON.stringify("data:"+data)
	var minder=new Minder(data);
	
	zr.add(minder);
	var stack=new Stack(30);
	toolBar.init(zr,stack);
	mindEvent.init(zr,stack,minder);
	
	minder.registerLayout('minder',new MinderLayout());
	
	minder.useLayout('minder');
	
	minder.getRoot().setPosition(300,300);    //设置根节点位置
	minder.getRoot().setData({
	        textFill:'#fff',
	        textPadding:[15,20,15,20],
	        fontSize:18,
	        textBackgroundColor:'#00aaff',
	        textBorderRadius:4,
	        textOffset:[10,6]
	 });
	
	minder.layout(minder.getRoot(),'right');  //思维导图 向两侧发散
	
	window.m=minder;
}

function loadTree() {
	$.ajax({
		url : "http://localhost:8081/tree/view?name=菜单配置",
		type : "GET",
		dataType: "json",
		success : function(data){
			console.log("success:"+(JSON.stringify(data)));
			initMinder(data);
		},
		error : function(xhr,status,error) {
			alert("request server failure!");
			console.log("error:"+status);
		}
	});
}

loadTree();
navigator.init();